import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';

class MarketTab {
  String text;
  String tab;

  MarketTab(this.text, this.tab);
}

//定义tab页基本数据结构
final List<MarketTab> thisTabs = <MarketTab>[
  new MarketTab('普通会员', 'general'),
  new MarketTab('尊贵VIP会员', 'vip'),
];

class NewMarketingTabNavigation extends StatelessWidget {
  NewMarketingTabNavigation({this.currentTab, this.onSelectTab});

  final MarketTab currentTab;
  final ValueChanged<MarketTab> onSelectTab; //这个参数比较关键，需仔细理解下

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 15.0),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: thisTabs.map((item) {
            return GestureDetector(
                child: Container(
                  decoration: _decorationTabMatch(item: item),
                  padding: EdgeInsets.fromLTRB(14.0, 2.0, 14.0, 2.0),
                  margin: EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
                  child: Text(
                    item.text,
                    style: TextStyle(
                        color: _colorTabMatching(item: item),
                        fontSize: ScreenUtil().setSp(32.0),
                        fontFamily: Font.PingFangMedium),
                  ),
                ),
                onTap: () => onSelectTab(
                      item,
                    ));
          }).toList()),
    );
  }

  //定义tab被选中和没被选中的颜色样式
  Color _colorTabMatching({MarketTab item}) {
    return currentTab == item ?Colours.baseBtnColor : Colours.tv9c;
  }

  Decoration _decorationTabMatch({MarketTab item}) {
    if (currentTab == item) {
      ///选中的样式
      return BoxDecoration(
        border: Border(bottom: BorderSide(color:Colours.baseBtnColor,width: ScreenUtil().setWidth(10)))
      );
    } /*else {
      ///未选中的样式
      return BoxDecoration(
          border: Border(bottom: BorderSide(color: Colours.c243,width: ScreenUtil().setWidth(10)))
      );
    }*/
  }
}
